//堆叠条形图 柱状图
<template>
  <div class="stackedHorizontalBar">
      <div class="bar-chart-right">
        <div class="bar-chart-main">
          <div class="bar-chart-right-content" v-for="(item,index) in echartData.series" :key="index"  @click="clickBar(index)">
            <div class="bar-chart-right-content-txt">{{item.name}}</div>
            <div class="bar-chart-right-content-line">
                <div class="bar-chart-right-line">
                    <!-- 各项统计加起来的占比 -->
                    <div class="bar-chart-right-line-bar" :style="`width:${(item.sum/Math.max(...echartData.sumCollect))* 100}%`">
                        <div v-for="(childItem,childIndex) in item.data" :key="childIndex" :class="{'bar': childItem > 0}" :style="`width:${(childItem/item.sum)* 100}%;background:${colorLegend[childIndex]}`"> </div>
                  </div>
                  <span class="bar-chart-right-line-txt">{{item.sum}}</span>
              </div>
           </div>
         </div>
       </div>
        <!--虚线-->
          <div class="bar-chart-right-dash">
            <div class="bar-chart-right-dash-line"  v-for="i in 4"  :key="i">
          </div>
        </div>
     </div>
      <!-- 底部 -->
      <div class="legend-row zs-space-4n-top">
          <template v-for="(item,index) in echartData.legend" :key="index" >
            <div class="legend-img zs-space-right-sm"  :style="`background:${colorLegend[index]}`"></div>
            <div class="zs-text-sm zs-text-gray-dark zs-space-right">{{ item }}</div>
        </template>
     </div>
 </div>
</template>

<script lang="js">
export default {
  name: 'stackedHorizontalBar',
  components: {},
  props:{
    barCanvas:{
      type:String,
      default:''
    },
    echartData:{
      type:Object,
      default:()=>{
        }
    },
    isShowPercentage:{
      type:Boolean,
      default: false
    },
    isShowChatData:{
      type:Boolean,
      default: true
    },
    colorLegend:{
      type:Array,
      default:()=>{
        ['#FF470A','#C09F88','#43C902','#CCCCCC','#8EA2EE']
      }
    }
  },
  data(){
    return{
       
    }
  },
  mounted () {
  },
  methods: {
    clickBar(index) {
      console.log('pcclickcb index=', index)
      this.$emit('clickChartCallBack', index)
    }
  }
}
</script>

<style>
.stackedHorizontalBar {
  width: 100%;
  display: flex;
  align-items: center;
  min-height: 60px;
  /* padding: 12px 0; */
  flex-wrap: wrap;
}
.legend-row{
  width: 100%;
  display: flex;
  align-items: center;
}
.legend-img{
  width: 10px;
  height: 5px;
  border-radius: 1px;
}
.stackedHorizontalBar .bar{
  border-right: 1px solid #fff;
  border-radius: 1px;
}
.stackedHorizontalBar .bar-chart-right .bar-chart-right-content{
  margin-bottom: 12px;
}
.stackedHorizontalBar .bar-chart-right .bar-chart-right-content:last-child{
  margin-bottom: 0;
}
 .stackedHorizontalBar .bar-chart-right-content{
 display: flex;
  align-items: center;
  justify-items: center;
  width: 100%;
  flex-wrap: wrap;
}
.stackedHorizontalBar .bar-chart-right-content-txt{
  width: 100%;
  margin-bottom: 4px;
  font-size: 12px;
  color: #333333;
  margin-left: 4px;
}
.stackedHorizontalBar .bar-chart-right-content-line{
  display: flex;
  align-items: center;
  justify-items: center;
  width: 100%;
}
.stackedHorizontalBar .bar-chart-right-line{
 flex-grow: 1;
  display: flex;
  align-items: center;
  /*flex-wrap: nowrap;*/
}
.stackedHorizontalBar .bar-chart-right-line-bar{
  height: 10px;
  background: #C09F88;
  border-radius: 1px;
  display: flex;
}
.stackedHorizontalBar .bar-chart-right-line-txt{
  min-width: 20px;
  height: 18px;
  font-size: 12px;
  font-family: PingFangSC, PingFangSC-Medium;
  font-weight: 500;
  text-align: left;
  color: #333333;
  line-height: 18px;
  margin-left: 4px;
}
.stackedHorizontalBar .bar-chart-right{
  border-left: 1px solid #cfd1d3;
  flex-grow: 1;
  position: relative;
  /* min-height: 220px; */
  display: flex;
  /*justify-content: center;*/
  align-items: center;
  /*flex-wrap: wrap;*/
}
.stackedHorizontalBar .bar-chart-right-dash-line{
  height: 100%;
  width: 25%;
  border-right:1px dashed #f2f2f2;
}
.stackedHorizontalBar .bar-chart-main{
  display: flex;
  z-index: 1;
  flex-wrap: wrap;
  /*min-height: 220px;*/
  position: relative;
  width: 100%;
}
.stackedHorizontalBar .bar-chart-right-dash{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  display: flex;
  z-index: 0;
}
.bar-chart-right-line-right{
  min-width: 60px;
  text-align: right;
}
.bar-chart-danger-txt {
  color: #ED1A2C;
}

.changeColor{
  background:#FF470A !important;
}
.changeTextColor{
  color:#FF470A !important
}
</style>
